//https://www.bilibili.com/video/BV1d54y1f7B3/?spm_id_from=333.337.search-card.all.click&vd_source=d6fe65f095f01f05591e89d810720ccc
// 2024-10-18


import java.util.Arrays;
import java.util.Scanner;

public class P003_删除排序数组中的重复项_双指针法 {

    public static void main(String[] args) {
        System.out.println(fun(new int[]{0, 1, 2, 2, 3, 3, 4}));
    }

    // 给个数组nums,原地删除重复出现的元素
    private static int fun(int[] nums) {
        if (nums.length == 0 || nums.length == 1) return nums.length;
        int i = 0;
        for (int j = i+1;j < nums.length;j++)
            if (nums[j] != nums[i]) // 不相等，才赋值给慢指针
                nums[++i] = nums[j];
        return i+1;
    }


}
